(function () {

    var gameId = utils.getParams(0);

    //绑定下载事件
    $('[data-download="openDownloadUrl"]').on('click',function (e) {
        e = e || event;
        var $btn = $(this),
            id = $btn.find('a').attr('data-download-id');
        if( id ){
            var newTab = window.open('about:blank');
            $.ajax({
                type: 'POST',
                url: '/game/ajax_get_url/' + id,
                data:{
                    game_id : gameId
                },
                success: function ( res ) {
                    if( res.ret === 0 ){
                        newTab.location.href = res.data.url;
                    }else{
                        alert( res.msg );
                        newTab.close();
                    }
                }
            })
        }
    });

    //绑定在线玩事件
    var $openPlayBtn = $('#onlinePlay');
    if( $openPlayBtn ){
        $openPlayBtn.on('click', function ( e ) {
            e = e || event;
            e.stopPropagation();
            changeTabs( 'tab0' );
            loginModel.open();
        });
    }

    function upholdText(selector) {
        selector.on("click",function () {
            selector.toggleClass('text-fold');
            var target = $('.game-text');
            target.toggleClass('height-auto');
        });
    }

    function main() {
        var swiper = new Swiper('.swiper-container', {
            pagination: '.swiper-pagination',
            nextButton: '.swiper-button-next',
            prevButton: '.swiper-button-prev',
            spaceBetween: 30
        });

        upholdText($('.text-upfold'));
    }
    main();
})();
